#pragma once
#include "../Global References/BaseObject.h"
#include "../Global References/Globals.h"
#include "../World/Entity/Local References.h"
#include "Recipe.hpp"
using namespace wordModify; 

enum ProjectileTypes{
	P_TYPE_PLAYER,	//Affects Enemies
	P_TYPE_ENEMY,	//Affects Players
	P_TYPE_GAIA		//Affects Everyone
};
enum EquipType
{
	HEAD,	//Helmet	- Defense				:INT Penalty
	BODY,	//Cuirass	- Defense				:CRD Penalty
	FIST,	//Gauntlets - Defense and Attack	:CRD Penalty
	BOOT,	//Feet		- Defense and Attack	:CRD Penalty
	TOOL,	//Hand or KA- Utility and Attack
	WEAP,	//Weapon	- Attack  and Utility
};

struct Item_Base : public BaseObject
{
	Vector2D iconAsset;		//What Icon to draw to the inventory
	short			itemType;		//How the entity should use the item
	char* 			itemName;		//The displayed name of the item
	short			skillAlignment;	//What skill the Item refers to.
	short 			skillRequisite;	//What the skill must be at to determing the effect of the item
	unsigned short	uniqueID;		//a unique identifer

	Item_Base();
	void _itemInit(short type, short skill, short requisite, char* name, Vector2D* ASSET = NULL);
	void _recipeInit(char* FileName, recipe* a_Recipe);
	void set(Item_Base i);
	void setUniqueId(int i){uniqueID = i;};
	void serialize(ByteBuffer*& info);
	void deserialize(ByteBuffer* info, int & index);

};
struct Item_Projectile : public Item_Base
{
	enum collideEffects
	{
		SPELL_PLACEBLOCK,
		SPELL_WEAPONRY,
		SPELL_FIREBALL,
		SPELL_MULTIPLAYER_DUD
	};
	short		range;			//How far the the object has left to live
	Vector2D	vector;			//Treats X and Y as Magnitude and lastXDir.
	Vector3D	pieDmg;
	short		originFlag;		//What sort of item it came from. If it's a spell
	short		collideEffect;	//Used to determine what to do when collided
	bool		movementOn;		//Whether or not to follow any movement
	bool		physicsOn;		//Whether or not to follow physics

	Item_Projectile();
	void _projectileInit(bool movement, bool physics, Vector3D PIE, Vector2D a_vector, short a_range, short ownerFlag);

	void update();
	short getPierce(){return short(pieDmg.x);}
	short getImpact(){return short(pieDmg.y);}
	short getEnergy(){return short(pieDmg.z);}
	void serialize(ByteBuffer* info);
	void deserialize(ByteBuffer* info, int & index);

};
struct Item_Consumable : public Item_Base
{
	/*Definiton: Something the player consumes for an effect. Such as scroll,
	potion, food, poison, etc. When consumed, the object will look at the 
	player's Resilience, check it against addictionLevel, roll, and see 
	if the player gets addicted. Withdrawls are the same for all things.*/

	int		usesLeft;		//How many bites, swigs, puffs, casts or w/e are left
	effect	effects;		//When the player consumes, they will recieve the effects and access them on update.

	Item_Consumable();
	void _fileInit(char* FileName, recipe* a_Recipe);
	void _copyInit(Item_Consumable* toCopy);

};
class Item_Equippable  : public Item_Base{
private:
	short m_extraData;	//Weapons: Range. Armor: CRD Penalty
	short m_pierce;		//For damage or defense, depending on type
	short m_impact;		//For damage or defense, depending on type
	short m_energy;		//For damage or defense, depending on type		
	short e_equipType;	//How to use the given stats, references type enum

public:


	bool  m_placeBlock;
	Vector2D secassetIndex; //In case of certain armor where two pieces will need to be replaced.
	void _copyInit(Item_Equippable* toCopy);
	void _fileInit(char* FileName, recipe* a_Recipe);
	void _equipInit(EquipType a_Type, short m_P, short m_I, short m_E, short a_Extra);
	void addPIE(short& a_pierce, short& a_impact, short& a_energy);
	void remPIE(short& a_pierce, short& a_impact, short& a_energy);

	//=====ACCESSORS
	Vector3D getPIE();
	short getRange();
	short getCRDPenalty();
	short getEquipType();

	void serialize(ByteBuffer*& info);
	void deserialize(ByteBuffer* info, int & index);
};
